package cc.mrbird.plan.service.impl;

import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.service.impl.BaseService;
import cc.mrbird.plan.dao.RehearseMapper;
import cc.mrbird.plan.domain.Rehearse;
import cc.mrbird.plan.service.RehearseService;
import cc.mrbird.system.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service("rehearseService")
public class RehearseServiceImpl extends BaseService<Rehearse> implements RehearseService {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private RehearseMapper rehearseMapper;
    /*@Override
    public List<Rehearse> findRehearses(Rehearse rehearse, QueryRequest request) {
        try {
            return this.rehearseMapper.findRehearseList(rehearse);
        } catch (Exception e) {
            log.error("error", e);
            return new ArrayList<>();
        }
    }*/

  /*  @Override
    public Rehearse findByName(String contact_name) {
        Example example = new Example(User.class);
        example.createCriteria().andCondition("lower(contact_name)=", contact_name.toLowerCase());
        List<Rehearse> list = this.selectByExample(example);
        return list.isEmpty() ? null : list.get(0);
    }*/

    @Override
    public void add(Rehearse rehearse) {
        this.save(rehearse);
    }

    @Override
    public void update(Rehearse rehearse) {
        this.updateNotNull(rehearse);
    }

    @Override
    public Rehearse findById(Integer id) {
        try {
            return this.rehearseMapper.findById(id);
        } catch (Exception e) {
            log.error("error", e);
            return new Rehearse();
        }
    }

    @Override
    @Transactional
    public void delete(String ids) {
        List<String> list = Arrays.asList(ids.split(","));
        this.batchDelete(list, "unit_id", Rehearse.class);
    }
}
